package com.cms.controller.front;

import java.util.List;

import com.cms.entity.Category;
import com.cms.interceptor.SiteInterceptor;
import com.cms.routes.RouteMapping;
import com.jfinal.aop.Before;

/**
 * Controller - 栏目
 * 
 * 
 * 
 */
@RouteMapping(url = "/category")
@Before(SiteInterceptor.class)
public class CategoryController extends BaseController {
	 public void index() {
	        Long categoryId = getParaToLong(0);
	        Category category = new Category().dao().findById(categoryId);
	        List<Category> number = null;
	        if (category.getGrade() != 0) {
	            Category parent = new Category().dao().findById(category.getParentId());
	            setAttr("son", new Category().dao().find("select * from cms_category where parentId =? order by sort",parent.getId()));
	            setAttr("sire", parent);
	        }
	        else {
	            setAttr("sire",category);
	            number = new Category().dao().find("select * from cms_category where parentId =? order by sort",categoryId);
	            setAttr("son",number);
	            if (number.size() > 0) {
	                category = new Category().dao().findById(number.get(0).getId());
	                setAttr("currentCategory", number);
	            }
	        }
	        Integer pageNumber = getParaToInt("pageNumber");
	        setAttr("currentCategory",category);
	        if (category.getType() == Category.PAGE_TYPE) {
	            render("/templates/" + getTheme(getCurrentSite().getId()) + "/" + category.getPageTemplate());
	        }
	        else {
	            if (pageNumber == null) {
	                pageNumber = 1;
	            }
	            setAttr("pageNumber",pageNumber);
	            render("/templates/" + getTheme(getCurrentSite().getId()) + "/" + category.getListTemplate());
	        }
	    }
	/**
	 * 栏目
	 */
	/*public void index() {
		Long categoryId = getParaToLong(0);
		Category category = new Category().dao().findById(categoryId);
		setAttr("currentCategory", category);
		if(category.getType()==Category.PAGE_TYPE){
			render("/templates/"+getTheme(getCurrentSite().getId())+"/"+category.getPageTemplate());
		}else{
			Integer pageNumber = getParaToInt("pageNumber");
			if(pageNumber==null){
				pageNumber = 1;
			}
			setAttr("pageNumber", pageNumber);
			render("/templates/"+getTheme(getCurrentSite().getId())+"/"+category.getListTemplate());
		}
	}*/
}
